﻿using System;
using System.Web;

namespace Catchbase.Service
{
    public class CatchbaseHttpModule : IHttpModule
    {
        public void Init(HttpApplication context)
        {
            context.BeginRequest += BeginRequest;
        }

        public void Dispose()
        {
            
        }

        private void BeginRequest(object sender, EventArgs e)
        {
            var application = (HttpApplication)sender;
            RewritePath(application.Context);
        }

        private void RewritePath(HttpContext context)
        {
            var path = new CatchbasePathHelper(context.Request.AppRelativeCurrentExecutionFilePath);
            context.RewritePath(path.FilePath, path.PathInfo, "", false);
        }
    }
}